﻿using System.Text;
using DictationTool.Common;

namespace TextCompare
{
    class StringTextMatcher : ITextMatcher
    {
        public StringTextMatcher(string source, string target)
        {
            this.Source = source;
            this.Target = target;
            this.source = source.SplictTo();
            this.target = target.SplictTo();

            SourceCount = this.source.Length;
            TargetCount = this.target.Length;
        }

        public string Source
        {
            get;
            private set;
        }

        public string Target
        {
            get;
            private set;
        }

        public int SourceCount
        {
            get;
            private set;
        }

        public int TargetCount
        {
            get;
            private set;
        }

        public bool Compare(int i, int j)
        {
            return source[i].Equals(target[j]);
        }

        public string GetSourceSubString(int startPoint, int endPoint)
        {
            return GetSubString(source, startPoint, endPoint);
        }

        public string GetTargetSubString(int startPoint, int endPoint)
        {
            return GetSubString(target, startPoint, endPoint);
        }

        private string GetSubString(string[] str, int start, int end)
        {
            StringBuilder stringBuilder = new StringBuilder();
            for (int i = start; i <= end; i++)
            {
                stringBuilder.Append(str[i]);
            }

            return stringBuilder.ToString();
        }

        private string[] source;
        private string[] target;
    }
}
